import Vue from "vue";
import * as echarts from 'echarts';
// 生成随机数 min最小值，max最大值
const randomRange = (min = 0, max = 10) => {
	return Math.floor(Math.random() * (max - min)) + min;
}

// 生成 uuid
const uuid = () => {
	var s = [];
	var hexDigits = "0,1,2,3,4,5,6,7,8,9,a,b,c,d,e,f";
	for (var i = 0; i < 36; i++) {
		s[i] = hexDigits.split(',')[parseInt(Math.random() * 16)];
	}
	return s.join("");
}

const gradientReturnString = (type, gradient) => {
	if (type == 'bg') {
		const colors = gradient.colors.toString();
		if (gradient.type === "linear-gradient") {
			return `linear-gradient(${gradient.angle}deg,${colors})`;
		}

		if (gradient.type === "radial-gradient") {
			return `radial-gradient(circle, #f8f7f733 10%, #409eff 80%)`;
		}
	} else if (type == 'echart') {
		if (gradient.type === "linear-gradient") {
			return new echarts.graphic.LinearGradient(0, 0, 0, 1, [
				{ offset: 0, color: gradient.colors[0] },
				{ offset: 1, color: gradient.colors[1] }
			])
		}
		if (gradient.type === "radial-gradient") {
			return new echarts.graphic.RadialGradient(0, 0, 1, 1, [
				{ offset: 0, color: gradient.colors[0] },
				{ offset: 1, color: gradient.colors[1] }
			])
		}
	} else {
		return 'none'
	}

}

Vue.prototype.$methods = {
	randomRange,
	uuid,
	gradientReturnString
};
